{% extends "orgs/base.html" %}
{% load attachment_tags %}
{% load attachment_inclusion_tag %}
{% load org_tags %}
{% load i18n %}



{% block head_title %}Meeting {{ meeting }} of {{ meeting.circle }}{% endblock %}

{% block body %}
<div style="width: 800px;">
	<div style="text-align: center; width: 60%;" >
		<h1>{{ meeting.get_name_display }} of <a href="{% url organization org_slug=meeting.circle.slug %}">{{ meeting.circle }}</a></h1>
		<h3>
			{{ meeting.date_and_time.date|date:"l, F d, Y" }}<br />
			{{ meeting.date_and_time.time|time:"P" }} at {{ meeting.location }}<br />
		</h3>
	</div>
    
	<div style="float: left; width: 30%; " >
		
	
		{% if is_officer %}
			<div>
				<form action="{% url meeting_edit meeting_slug=meeting.slug %}" method="GET">
					<input class="submit-btn" type="submit" value="{% trans "Edit Meeting" %}" />
				</form>
			</div>
		
			{% comment %}
			{% if meeting_started %}
				{% if is_secretary %}	
					<div style="margin-top: 1em; margin-bottom: 2px; " >
						<b>Attendance:</b> 
						<form style="display: inline;" action="{% url meeting_attendance meeting_slug=meeting.slug %}" method="GET">
							<input class="submit-btn" type="submit" value="View" />
						</form>
						<form style="display: inline;" action="{% url update_attendance meeting_slug=meeting.slug %}" method="GET">
							<input class="submit-btn" type="submit" value="Update" />
						</form>
				</div>
				{% endif %}
			{% endif %}
			{% endcomment %}

		{% endif %}
			
		<div>
			<h2>{% trans "Roster of Current Circle Members" %}</h2>
			<table style="margin-bottom: 2em; " >
				{% for member in meeting.circle.members.all %}
				<tr>
					<td>
						<a href="{% url profiles.views.profile member.user.username %}" title="{{ member.user_name }}">{{ member.user_name }}</a>
					</td>
					<td style="padding-left: 4px; " >
						{{ member.get_role_display }}
					</td>
				</tr>
				{% endfor %}
			</table>
		</div>		
	</div>

	<div style="float:left; margin-left: 1em; width: 50%; text-align: center;" >
		
		{% if is_officer %}
		
			<h1 style="text-align: center; " >{% trans "Agenda" %}</h1>
		
			<div class="form-toggle" style="text-align: left; " >
				<h2>
					<a href=""  id="add-item-toggle">{% trans "Add Agenda Item" %}</a>
					&nbsp;
					<a href="{% url meeting_agenda meeting_slug=meeting.slug %}">Printable/Preview</a>
					
					<form style="display: inline; padding-left: 2px; padding-right: 2px;" action="{% url announce_meeting meeting_slug=meeting.slug %}" method="POST">
						<input class="submit-btn" type="submit" value="Email Agenda" />
						<input type="hidden" name="next" value="{% url meeting_details meeting_slug=meeting.slug %}" />
					</form>

					<form id="add-item" action="{% url meeting_details meeting_slug=meeting.slug %}" method="POST">
						<table>
							{{ topic_form.as_table }}
							<tr><td>&nbsp;</td><td><input class="submit-btn" type="submit" value="{% trans "Add Item" %}" /></td></tr>
						</table>
						<input type="hidden" name="next" value="{{ request.path }}" />
					</form>
				</h2>
			</div>

			{% if meeting.agenda_approved %}
				
			{% else %} 
				{% if topics %}
					{% if is_officer %}				
						<div style="margin-bottom: 1em; margin-top: 4px; " >
							<form action="{% url agenda_approval meeting_slug=meeting.slug %}" method="POST">
								<input class="submit-btn" type="submit" value="Publish Agenda" />
								<input type="hidden" name="next" value="{% url meeting_details meeting_slug=meeting.slug %}" />
							</form>
						</div>
						<a href="{% url meeting_agenda meeting_slug=meeting.slug %}">Printable agenda</a>
					{% comment %}
					{% else %}
						{% if is_secretary %}				
							<div style="margin-bottom: 1em; margin-top: 4px; " >
								<form action="{% url request_agenda_approval meeting_slug=meeting.slug %}" method="POST">
									<input class="submit-btn" type="submit" value="Request Agenda Approval" />
									<input type="hidden" name="next" value="{% url meeting_details meeting_slug=meeting.slug %}" />
								</form>
							</div>
						{% endif %}
						{% if is_opleader %}				
							<div style="margin-bottom: 1em; margin-top: 4px; " >
								<form action="{% url agenda_approval meeting_slug=meeting.slug %}" method="POST">
									<input class="submit-btn" type="submit" value="Approve Agenda" /> Announcement will be sent to community
									<input type="hidden" name="next" value="{% url meeting_details meeting_slug=meeting.slug %}" />
								</form>
							</div>
						{% endif %}
					{% endcomment %}
					{% endif %}
				{% endif %}
			{% endif %}
			{% if topics %}
				<h3 style="text-align: center; " >{% trans "Administrative Items" %}</h3>
				<table>
					{% for item in meeting.agenda_boilerplate %}
						<tr>
							<td style="text-align: left; " >{{ forloop.counter }}) {{ item }}</td>
						</tr>
					{% endfor %}
				</table>
		
				<h3 style="text-align: center; " >{% trans "Agenda Items" %}</h3>
				<table class="bordered-table" >
					<tr>
						<th>Order</th>
						<th>Agenda Item</th>
						<th>Type</th>
						<th>Lead</th>
					</tr>
					{% for topic in topics %}
						{% if topic.order %}
							<tr>
								<td>{{ topic.order }}</td>							
								<td><a href="{% url meeting_topic topic.id %}">{{ topic.title }}</a></td>
								<td>{{ topic.type }}</td>
								<td>
									{% if topic.lead %}
										<a href="{% url profiles.views.profile topic.lead.username %}">{{ topic.lead_name }}</a>
									{% else %}
										&nbsp;
									{% endif %}
								</td>
								<td>
									<form method="POST" action="{% url meeting_topic_edit topic.id %}">
										<input class="submit-btn" type="submit" value="{% trans "edit" %}" />
										<input type="hidden" name="next" value="{% url meeting_details meeting_slug=topic.meeting.slug %}" />
									</form>
								</td>
								<td>
									<form method="POST" action="{% url meeting_topic_delete topic.id %}">
										<input class="submit-btn" type="submit" value="{% trans "delete" %}" />
										<input type="hidden" name="next" value="{% url meeting_details meeting_slug=topic.meeting.slug %}" />
									</form>
								</td>
							</tr>
							{% if topic.body %}
								<tr>
									   <td colspan="5" style="text-align: left; padding-left: 16px; " >
										 {{ topic.body|linebreaks }}
									 </td>
								 </tr>
							{% endif %}
							{% get_attachments for topic as attachments %}
							{% if attachments %}
								<tr><td colspan="5">
									<table style="margin-top: 0; margin-bottom: 0; margin-left: 4em;" >
										<tr><th colspan="2" >Attachments:</th></tr>
										{%  for attachment in attachments %}
											<tr>
												<td>
													<a href="{{ attachment.file_url }}">{{ attachment.title  }}</a>
												</td>
												<td style="padding-left: 1em; " >{{ attachment.summary }}</td>
											</tr>
										{% endfor %}
									</table>
								</td></tr>
							{% endif %}
						{% else %}
							<tr>
								<td>&nbsp;</td>
								<td style="text-align: left; " >{{ topic.title }}</td>
								<td colspan="3" >&nbsp;</td>
							</tr>
						{% endif %}
					{% endfor %}
				</table>
			{% endif %}
		
		{% else %}
			{% if meeting.agenda_approved %}
				
				{% if topics %}
					<h1 style="text-align: center; " >{% trans "Agenda" %}</h1>
					<a style="text-align: center; margin-bottom: 8px; "  
						href="{% url meeting_agenda meeting_slug=meeting.slug %}">Printable agenda
					</a>
	
					<h3 style="text-align: center; " >{% trans "Administrative Items" %}</h3>
					<table>
						{% for item in meeting.agenda_boilerplate %}
							<tr>
								<td style="text-align: left; " >{{ forloop.counter }}) {{ item }}</td>
							</tr>
						{% endfor %}
					</table>
			
					<h3 style="text-align: center; " >{% trans "Agenda Items" %}</h3>
					<table class="bordered-table" >
						
						<tr>
							<th>Agenda Item</th>
							<th>Type</th>
							<th>Lead</th>
						</tr>
						{% for topic in topics %}
							<tr>						
								<td style="text-align: left;" >{{ forloop.counter }}) {{ topic.title }}</td>
								<td>{{ topic.type }}</td>
								<td>
									{% if topic.lead %}
										<a href="{% url profiles.views.profile topic.lead.username %}">{{ topic.lead_name }}</a>
									{% else %}
										&nbsp;
									{% endif %}
								</td>
							</tr>
							{% if topic.body %}
								 <tr>
									 <td colspan="3" style="text-align: left;" >
										 {{ topic.body|linebreaks }}
									 </td>
								 </tr>
							 {% endif %}
							{% get_attachments for topic as attachments %}
							{% if attachments %}
								<tr><td colspan="3">
									<table style="margin-top: 0; margin-bottom: 0; margin-left: 4em;" >
										<tr><th colspan="2" >Attachments:</th></tr>
										{%  for attachment in attachments %}
											<tr>
												<td>
													<a href="{{ attachment.file_url }}">{{ attachment.title  }}</a>
												</td>
												<td style="padding-left: 1em; " >{{ attachment.summary }}</td>
											</tr>
										{% endfor %}
									</table>
								</td></tr>
							{% endif %}
						{% endfor %}
					</table>
				{% endif %}
		
			{% else %}
				<h2 style="text-align: center; " >{% trans "Agenda To Be Posted" %}</h2>
		
				<h3>Members responsible for posting agenda:</h3>
				<ul>
					{% for member in meeting.circle.officers %}
						<li>
							<a href="{% url profiles.views.profile member.user.username %}" title="{{ member.user_name }}">{{ member.user_name }}</a>
							{{ member.get_role_display }}
						</li>
	
					{% endfor %}
				</ul>
					
			{% endif %}
		{% endif %} 
		
	</div>
	<div style="clear: both; padding-top: 1em; ">
		<hr />
		{% attachments meeting %}
	</div>
</div
    
{% endblock %}

{% block extra_body %}
	{{ block.super }}
    <script type="text/javascript">
        $(document).ready(function() {
            $('#add-item').hide();
            $('#add-item-toggle').click(function() {
                $('#add-item').slideToggle();
                $('#add-item').autoscroll();
                return false;
            });
            if ($('#add-item ul.errorlist').length) {
                $('#add-item').show();
                $('#add-item ul.errorlist').autoscroll();
            };
        });
    </script>
{% endblock %}